<%@page import="entities.Category"%>
<%@page import="entities.Link"%>
<%@page import="java.util.List"%>
<%@page import="helpers.PaginatorHelper"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="java.util.ArrayList"%>
<%
List<Link> links = (List<Link>) request.getAttribute("links");
List<Category> categories = (List<Category>) request.getAttribute("categories");
String cid = (String) request.getAttribute("cid");
int pages = (Integer) request.getAttribute("page");
boolean nextPage = (Boolean) request.getAttribute("nextPage");
boolean prevPage = (Boolean) request.getAttribute("prevPage");
PaginatorHelper paginator = (PaginatorHelper) request.getAttribute("paginator");
%>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/admin/layouts/header.jsp" />

<script type="text/javascript" src="/admin/js/custom/link_list.js"></script>
<script type="text/javascript">
<!--
var server = "<%=UrlHelper.getServerUrl(request)%>";
var cid = "<%=cid%>";
//-->
</script>
				<jsp:include page="/admin/elements/heading_panel.jsp" />

                <!-- Build page from here: -->
                <div class="row-fluid">
					<div class="span12">
						<jsp:include page="/admin/elements/message_box.jsp" />
					
                    	<div class="box">
                        	<div class="title">
                                <h4>
                                    <span class="icon16 icomoon-icon-list-view"></span>
                                    <span>List Link</span>
                                </h4>
                                <a href="#" class="minimize">Minimize</a>
                            </div>
                            <div class="content">
                            	<div class="dataTables_length">
                            		<label class="row-fluid">
	                            		<div class="span9">
		                            		<select class="action-value nostyle">
		                            			<option value="status_active">Change to Status Active</option>
												<option value="status_pending">Change to Status Pending</option>
						                        <option value="status_inactive">Change to Status Inactive</option>
						                        <option value="delete">Delete all selected</option>
						                    </select>
						                </div>
						                <div class="span3">
							                <button class="btn apply-change">Apply</button>
							            </div>
					                </label>
                            	</div>
                            	
                            	
                            	<div class="dataTables_filter right">
									<form method="get">
										<label class="row-fluid">
											<div class="span6">
												<select name="cid" class="nostyle">
													<option value="">(TOP)</option>
													<%
													for (int i = 0; i < categories.size(); i++) {
													%>
													<option value="<%=categories.get(i).getId()%>">
														|<% for (int j = 2 ; j <= categories.get(i).getLevel(); j++) {%> |<% } %>___
														<%=categories.get(i).getName()%> (<%=categories.get(i).getLevel()%>)
													</option>
													<%
													}
													%>
												</select>
											</div>
											<div class="span6">
												<button class="btn gray" type="submit">Change Category</button>
											</div>
										</label>
									</form>
								</div>
										
								
                                <table class="responsive table table-bordered" id="checkAll">
                                    <thead>
                                      <tr>
                                        <th>Id</th>
                                        <th>Title</th>
                                        <th>Category</th>
                                        <th>Status</th>
                                        <th>Type</th>
                                        <th id="masterCh" class="ch"><input type="checkbox" class="checkall styled" value="all"></th>
                                        <th>Actions</th>
                                      </tr>
                                    </thead>
                                    <tbody>
                                      <% for (int i = 0; i < links.size(); i++) { %>
                                      <tr>
                                        <td><%=links.get(i).getId() %></td>
                                        <td><%=links.get(i).getName() %></td>
                                        <td><%=links.get(i).getCategory() %></td>
                                        <td>
                                        <%
											switch (links.get(i).getStatus()) {
												case 0: 
													%>Inactive<%
													break;
												case 1:
													%>Pending<%
													break;
												case 2:
													%>Active<%
													break;
												default:
													break;
											}
										%>
                                        </td>
                                        <td><%=links.get(i).getType() %></td>
                                        <td class="chChildren"><input type="checkbox" value="<%=links.get(i).getId()%>" class="styled"></td>
                                        <td>
                                            <div class="controls center">
                                                <a href="/admin/link/edit/<%=links.get(i).getId()%>" title="Edit Link" class="tip"><span class="icon12 icomoon-icon-pencil"></span></a>
                                                <a href="/admin/link/delete/<%=links.get(i).getId()%>" title="Remove Link" class="tip delete"><span class="icon12 icomoon-icon-remove"></span></a>
                                            </div>
                                        </td>
                                      </tr>
                                      <% } %>
                                    </tbody>
                                </table>
                            </div>
						</div><!-- End .box -->
						
						<ul class="pager">
							<% if (prevPage) { %>
							<li>
                                <a href="<%=paginator.getPrev()%>">Previous</a>
                            </li>
							<% }%>
                            <% if (nextPage) { %>
                             <li>
                                <a href="<%=paginator.getNext()%>">Next</a>
                            </li>
                            <%}%>
                        </ul>
						
					</div><!-- End .span6 -->

				</div><!-- End .row-fluid -->
                
<jsp:include page="/admin/layouts/footer.jsp" />